package com.dragon.design.pattern.creational.singleton;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * 容器单例模式
 *
 * @author dragon
 * @version V1.0.0-RELEASE
 * @date 2019/5/16 11:17
 */
public class ContainerSingleton {

    private static Map<String, Object> singletonMap = new HashMap<>();

    private ContainerSingleton() {
    }

    public static void putInstance(String key, Object value) {
        if (key == null || "".equals(key) || value == null) {
            return;
        }
        if (!singletonMap.containsKey(key)) {
            singletonMap.put(key, value);
        }
    }

    public static Object getInstance(String key) {
        return singletonMap.get(key);
    }
}
